<?php

/**
 * Ajax box
 *
 * @author Raymond Benc aka natio <www.raybenc.com>
 * @copyright phpFoX
 * @package Mod_Video
 */
class PhpFox_Mod_Video_ComponentAjaxBox extends BaseComponent
{
    function process()
    {
     	$sType = $this->getParam('sType');

     	if ( !$sType )
     	{
     		return '';
     	}

     	switch($sType)
     	{
     		case 'featured':
     		$sQ = " v.featured = '1' ";
     		break;
     		case 'most_viewed':
     		$sOrder = " v.vid_total DESC ";
     		break;
     		case 'most_comments':
     		$sOrder = " v.comments DESC ";
     		break;
     		case 'rating':
     		$sOrder = " v.vid_rating DESC ";
     		break;
     	}

		$iTotal = (App::getParam('vid_abox_total') ? App::getParam('vid_abox_total') : 8);

		$aItems = $this->oDatabase->getRows("SELECT v.vid_id, v.vid_title, v.vid_info, v.vid_time, v.vid_total, v.vid_rating, v.duration, u.user, l.list_id, l.list_name FROM
			". App::getT('videos') ." AS v
			JOIN ". App::getT('user') ." AS u ON(v.vid_userid = u.id)
			LEFT JOIN ". App::getT('videos_list') ." AS l ON(v.vid_list_id = l.list_id)
			". (isset($sQ) ? "WHERE ". $sQ ."" : '') ."
			". (isset($sOrder) ? "ORDER BY ". $sOrder ."" : 'ORDER BY v.vid_time DESC') ."
			LIMIT 0,". $iTotal ."
			");

		$oSrvVideo = &App::getModuleService('Video', 'Video');
		$aContent = array();
		foreach($aItems as $aItem)
		{
			$aItem['vid_info'] = strip_tags($aItem['vid_info']);
			$aItem['stars'] = $oSrvVideo->prepareStars($aItem['vid_rating']);
			$aContent[] = $aItem;
		}

     	$this->oTpl->assignSrc(array
     	(
     		'sViewMore' => App::format('Mod_Video.see_more_videos', App::format('Mod_Video.ajaxbox.'. $sType .'')),
     		'sGImageUrl' => App::getParam('video.image.url'),
     		'sType' => $sType,
     		'aItems' => $aContent,
     		'iTotal' => $iTotal
     	));

		return $this->oTpl->fetch('AjaxBox.html');
    }
}

?>